﻿/**
 * Intro.cs - Welcome screen and main menu
 * 
 * Part of BoulderDAM - A BoulderDash clone using C# and SDL
 * Nacho Cabanes & students of DAM IES San Vicente, 2014
 * 
 * Revisions
 * #     Date         Creator, changes
 * ----  -----------  -------------------------------------------------------
 * 0.01  02-apr-2014  Nacho Cabanes: User can enter the Help Screen, Credits
 *                        screen or a Game
 * 0.03  03-apr-2014  Nacho Cabanes: Banner image, access to config and TopTen
 *                        PopUp (when implemented) before config screen
 * 0.04  07-apr-2014  Javier Soler, Luis Masso, Reinaldo Ferreira: 
 *                        Mouse: Full implemented.
 */

namespace Boulder
{
    class Intro
    {
        Font font18;
        Sprite banner;

        public Intro()
        {
            font18 = new Font("data/Joystix.ttf", 18);
            banner = new Sprite("data/boulder_intro.png");
        }

        public void Run()
        {
            int x = 70, y = 50;
            bool exit = false;

            do
            {
                Hardware.ClearScreen();
                banner.MoveTo(x, y);
                banner.DrawOnHiddenScreen();

                Hardware.WriteHiddenText("SPACE to start",
                    400, 520,
                    0xCC, 0xCC, 0xCC,
                    font18);
                Hardware.WriteHiddenText("H for Help",
                    430, 550,
                    0xAA, 0xAA, 0xAA,
                    font18);
                Hardware.WriteHiddenText("C for Credits",
                    410, 580,
                    0x88, 0x88, 0x88,
                    font18);
                Hardware.WriteHiddenText("T for Top Ten",
                    410, 610,
                    0x88, 0x88, 0x88,
                    font18);
                Hardware.WriteHiddenText("S for Settings",
                    410, 640,
                    0x88, 0x88, 0x88,
                    font18);
                Hardware.WriteHiddenText("Q to Quit",
                    440, 670,
                    0x66, 0x66, 0x66,
                    font18);
                
                Hardware.ShowHiddenScreen();

                Hardware.Pause(40);

                

                if (Hardware.KeyPressed(Hardware.KEY_C))
                {
                    CreditsScreen creditsScreen = new CreditsScreen();
                    creditsScreen.Run();
                }
                
                if (Hardware.KeyPressed(Hardware.KEY_H))
                {
                    HelpScreen helpScreen = new HelpScreen();
                    helpScreen.Run();
                }

                if (Hardware.KeyPressed(Hardware.KEY_T))
                {
                    HiScoresScreen hiScores = new HiScoresScreen();
                    hiScores.Run();
                }

                if (Hardware.KeyPressed(Hardware.KEY_S))
                {
                    // Settings via Pop-Up, just to test...  ;-)
                    if (Hardware.ShowPopUp("Enter configuration? (Y/N)",
                        Hardware.KEY_N, Hardware.KEY_Y) == Hardware.POPUP_OK)
                    {
                        ConfigScreen settings = new ConfigScreen();
                        settings.Run();
                    }
                }

                if (Hardware.KeyPressed(Hardware.KEY_SPC))
                {
                    Game myGame = new Game();
                    myGame.Run();
                }

                if (Hardware.KeyPressed(Hardware.KEY_Q))
                {
                    exit = true;
                }



                if (Hardware.MouseClicked())
                {
                    int MouseX = Hardware.GetMouseX();
                    int MouseY = Hardware.GetMouseY();

                    //Link SPACE to start
                    if ((MouseX >= 400 && MouseX <= 620) &&
                        (MouseY >= 520 && MouseY < 550))
                    {

                        Hardware.WriteHiddenText("SPACE to start",
                        400, 520,
                        0x33, 0xEE, 0x2C,
                        font18);
                        Hardware.ShowHiddenScreen();
                        Hardware.Pause(400);
                        
                        Game myGame = new Game();
                        myGame.Run();
                    }

                    //H for Help
                    if ((MouseX >= 430 && MouseX <= 600) &&
                        (MouseY >= 550 && MouseY < 580))
                    {
                        Hardware.WriteHiddenText("H for Help",
                        430, 550,
                        0x33, 0xEE, 0x2C,
                        font18);
                        Hardware.ShowHiddenScreen();
                        Hardware.Pause(400);

                        HelpScreen helpScreen = new HelpScreen();
                        helpScreen.Run();
                    }

                    // C for Credits
                    if ((MouseX >= 410 && MouseX <= 600) &&
                        (MouseY >= 580 && MouseY < 610))
                    {
                        Hardware.WriteHiddenText("C for Credits",
                        410, 580,
                        0x33, 0xEE, 0x2C,
                        font18);
                        Hardware.ShowHiddenScreen();
                        Hardware.Pause(400);

                        CreditsScreen creditsScreen = new CreditsScreen();
                        creditsScreen.Run();
                    }

                    //T for Top Ten
                    if ((MouseX >= 410 && MouseX <= 600) &&
                        (MouseY >= 610 && MouseY < 640))
                    {
                        Hardware.WriteHiddenText("T for Top Ten",
                         410, 610,
                          0x33, 0xEE, 0x2C,
                        font18);
                        Hardware.ShowHiddenScreen();
                        Hardware.Pause(400);

                        HiScoresScreen hiScores = new HiScoresScreen();
                        hiScores.Run();
                    }

                    //S for Settings
                    if ((MouseX >= 410 && MouseX <= 600) &&
                       (MouseY >= 640 && MouseY < 670))
                    {
                        Hardware.WriteHiddenText("S for Settings",
                        410, 640,
                        0x33, 0xEE, 0x2C,
                        font18);
                        Hardware.ShowHiddenScreen();
                        Hardware.Pause(400);

                        // Settings via Pop-Up, just to test...  ;-)
                        if (Hardware.ShowPopUp("Enter configuration? (Y/N)",
                            Hardware.KEY_N, Hardware.KEY_Y) == Hardware.POPUP_OK)
                        {
                            ConfigScreen settings = new ConfigScreen();
                            settings.Run();
                        }

                    }

                    //Q exit
                    if ((MouseX >= 410 && MouseX <= 600) &&
                      (MouseY >= 670 && MouseY < 700))
                    {
                        Hardware.WriteHiddenText("Q to Quit",
                        440, 670,
                         0x33, 0xEE, 0x2C,
                        font18);
                        Hardware.ShowHiddenScreen();
                        Hardware.Pause(400);

                        exit = true;
                    }


                }

            }
            while (!exit);
        }
    }
}
